@echo off
setlocal

:: command line support
:: (help mode)
if "%1"=="/?" (
  set HELP_MODE=true
  :: (implies console mode)
  set CONSOLE_MODE=true
  goto help
)
:: (help mode - be permissive and accept common "-h" switch also)
if "%1"=="-h" (
  set HELP_MODE=true
  :: (implies console mode)
  set CONSOLE_MODE=true
  goto help
)
:: (help mode - be permissive and accept common "--help" switch also)
if "%1"=="--help" (
  set HELP_MODE=true
  :: (implies console mode)
  set CONSOLE_MODE=true
  goto help
)
:: (avoid interfeerence with pre-existent console session - no color and mode changes, no clear screen, etc.)
if "%1"=="/console" (
  set CONSOLE_MODE=true
  :: (avoid jumping into an invalid location afterwards)
  goto setup
)
:: (disable plug-in support)
if "%1"=="/disable" (
  goto disable
)
:: (simply change active plug-in and quit)
if not "%1"=="" (
  set COMMAND_LINE_MODE=true
  :: NOTE: no user input check is performed!
  goto %1
)

:: setup environment
:setup
if not "%CONSOLE_MODE%"=="true" (
  mode con cols=80 lines=25
  color 17
)

:: welcome note
:menu
:: (avoid displaying menu when using command line version)
if "%COMMAND_LINE_MODE%"=="true" (
  echo Active plug-in: %ACTIVE_PLUGIN%
  goto quit
)
if not "%CONSOLE_MODE%"=="true" (
  cls
)
echo.
echo =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
echo        SVGSwitcher - Active SVG plug-in changer utility - $Revision: 5 $
echo =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if not "%ACTIVE_PLUGIN%"=="" (
  title %ACTIVE_PLUGIN% - SVGSwitcher
  echo.
  echo Active plug-in: %ACTIVE_PLUGIN%
) else (
  if not "%CONSOLE_MODE%"=="true" (
    title SVGSwitcher
  )
)
if not "%USER_NOTICE%"=="" (
  echo %USER_NOTICE%
)
echo.
echo Available options:
echo.
echo (1) Adobe SVG Viewer 6.0 Development Release 1 (a.k.a. ASV6)
echo (2) Adobe SVG Viewer 3.03 (a.k.a. ASV3)
echo (3) GPAC
echo (4) Ssrc SVG 9.0.1
echo (5) Corel SVG Viewer 2.1 (a.k.a. CSV)
echo (6) Renesis Player 1.1.1
echo (7) Renesis Player V3 beta (a.k.a. V3)
echo (8) SVG Map Toolkit (a.k.a. SMT)
echo (9) Abbra Pagefire
echo.
echo (d) Disable all supported plug-ins
echo (i) Installer download locations
echo (h) Help
echo (c) Change log
echo (q) Quit
echo.
:: (allow easily spotting whenever enter key was pressed - blank option is not a valid one)
set choice=[blank]
set /P choice=Please type the desired option and press enter . . . 
:: (plug-ins)
if "%choice%"=="1" goto ASV6
if "%choice%"=="2" goto ASV3
if "%choice%"=="3" goto GPAC
if "%choice%"=="4" goto SsrcSVG
if "%choice%"=="5" goto CSV
if "%choice%"=="6" goto Renesis
if "%choice%"=="7" goto V3
if "%choice%"=="8" goto SMT
if "%choice%"=="9" goto APF
:: (support options - using case-insensitive approach to be more permissive)
if "%choice%"=="d" goto disable
if "%choice%"=="D" goto disable
if "%choice%"=="h" goto help
if "%choice%"=="H" goto help
if "%choice%"=="c" goto changes
if "%choice%"=="C" goto changes
if "%choice%"=="i" goto installer
if "%choice%"=="I" goto installer
if "%choice%"=="q" goto quit
if "%choice%"=="Q" goto quit
:: (deal with missing or invalid option)
echo Unknown option: %choice%
pause
goto menu

:ASV6
"%SystemRoot%\system32\regsvr32.exe" /s "%CommonProgramFiles%\Adobe\SVG Viewer 6.0\NPSVG6.dll"
if "%ACTIVE_PLUGIN%"=="ASV3" (
  :: NOTE: forcing disable of both ASV3 and ASV6 doesn't help working around the browser restart/tab reload
  set USER_NOTICE=Fully switching from ASV3 requires a browser restart!
) else (
:: NOTE: ASV switch notice is always displayed as we don't detect active plug-in during startup
  set USER_NOTICE=Note: when switching from ASV3, browser must be restarted.
)
set ACTIVE_PLUGIN=ASV6
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:ASV3
"%SystemRoot%\system32\regsvr32.exe" /s "%CommonProgramFiles%\Adobe\SVG Viewer 3.0\NPSVG3.dll"
if "%ACTIVE_PLUGIN%"=="ASV6" (
  :: NOTE: forcing disable of both ASV3 and ASV6 doesn't help working around the browser restart/tab reload
  set USER_NOTICE=Fully switching from ASV6 requires a browser restart!
) else (
  :: NOTE: ASV switch notice is always displayed as we don't detect active plug-in during startup
  set USER_NOTICE=Note: when switching from ASV6, browser must be restarted.
)
set ACTIVE_PLUGIN=ASV3
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:GPAC
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\GPAC\GPAX.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=GPAC
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
 goto menu

:SsrcSVG
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\Savarese Software Research Corporation\Ssrc SVG Plugin v9.0.1\mozctlx.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=Ssrc SVG
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:CSV
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\Corel\Corel SVG Viewer\NPViewerPlugin.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=CSV
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:Renesis
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisX.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=Renesis
goto menu

:V3
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\Renesis Player\XRenesis.dll"
:: THINK: does V1/V3 support toggling or should we display a notice similar to ASV3/6 switch?
:: (apparently toggling seems to work as expected but currently V3 crashes so it's not straightforward to test for this)
set USER_NOTICE=
set ACTIVE_PLUGIN=Renesis V3
:: NOTE: apparently V3 doesn't mess up with the Renesis Windows File Explorer Plug-in but more tests are needed
:: (see other plug-ins)
goto menu

:SMT
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\SVGMapConsortium\SVGMapToolkit\SVGMap.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=SVG Map Toolkit
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:APF
"%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\Pagefire\Vidualize.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=Pagefire
if exist "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll" (
  :: (if present, restore Renesis Windows File Explorer Plug-in, usually disabled when a plug-in switch occurs)
  "%SystemRoot%\system32\regsvr32.exe" /s "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
)
goto menu

:disable
:: NOTE: this special option unregisters all supported plug-ins
::       (useful for testing content fallback)
:: TODO: if we know which is the active plug-in this can be improved
::       (no need to disable all plug-ins, only the currently active)
:: THINK: should we be disabling Renesis Windows File Explorer Plug-in also?
::        (it's a bit off-topic of in the scope of browser plug-ins but...)
"%SystemRoot%\system32\regsvr32.exe" /s /u "%CommonProgramFiles%\Adobe\SVG Viewer 6.0\NPSVG6.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%CommonProgramFiles%\Adobe\SVG Viewer 3.0\NPSVG3.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\GPAC\GPAX.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\Savarese Software Research Corporation\Ssrc SVG Plugin v9.0.1\mozctlx.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\Corel\Corel SVG Viewer\NPViewerPlugin.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\examotion\RENESIS\Player\RenesisX.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\examotion\RENESIS\Player\RenesisWS.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\examotion\Renesis Player\XRenesis.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\SVGMapConsortium\SVGMapToolkit\SVGMap.dll"
"%SystemRoot%\system32\regsvr32.exe" /s /u "%ProgramFiles%\Pagefire\Vidualize.dll"
set USER_NOTICE=
set ACTIVE_PLUGIN=[disabled]
goto menu


:help
if not "%CONSOLE_MODE%"=="true" (
  cls
)
echo.
echo Help
echo -----
echo This utility allows having multiple SVG plug-ins installed, easily switching
echo among them whenever needed. Very useful, for example, to conduct compatibility
echo tests with popular SVG implementations.
echo.
echo It is assumed that supported plug-in(s) are installed in the default location.
echo If a location other than the default is used, the plug-in(s) need to be
echo reinstalled using the default location (or the utility tweaked in accordance).
echo.
echo Command-line usage:
echo   "SVGSwitcher [plugin | [/disable | /console | /?] ]"
echo.
echo   "plugin"    Sets a plug-in as active and quits. Can be one of:
echo               ASV6, ASV3, GPAC, SsrcSVG, CSV, Renesis, V3, SMT, APF.
echo   "/disable"  Disables all supported plug-ins.
echo   "/console"  Skips color/title changes and clear screen operations, improving
echo               integration with a previously existent console session.
echo   "/?"        Displays this help screen.
echo.
echo Using no parameters causes the utility to to run in interactive mode (default).
echo.
if "%HELP_MODE%"=="true" (
  :: (avoid returning to the menu system)
  goto quit
)
pause
goto menu


:changes
if not "%CONSOLE_MODE%"=="true" (
  cls
)
echo.
echo Change Log
echo ----------
:: TODO: detect active plug-in during startup
::       (this might be possible through registry sniffing)
:: TODO: add support for improved namespace support within IE8
::       ( http://msdn.microsoft.com/en-us/library/dd565690(VS.85).aspx )
::       (this will require detecting IE version and guessing configurations for each supported plug-in)
::       (this will also require outputing a warning as this will not be performed by the default plug-in installations)
:: THINK: can eSVG ( http://esvg.ultimodule.com/ ) be supported also?
::        (apparently not, as it doesn't seem to register for default handler for svg+xml)
::        (only way to make use of the control seems to be using its specific "classId")
::        (although it may be possible through registry hacking, it will not be compatible with the default plug-in installation)
:: NOTE: please update the change log (and the title information) when making changes!
:: THINK: add support for 64-bit Windows versions?
::        (it's necessary to distinguish which plug-ins are 64-bit capable)
::        (at least requires detection and rework of ProgramFiles/CommonProgramFiles based target folders)
:: TODO: detect if running with administrative privileges, else operations will (likely) fail in Vista and 7 with UAC enabled
echo 1.7 - Helder Magalhaes, January 2012
echo       Added support for Abbra Pagefire;
echo       Updated Ssrc SVG plug-in to 9.0.1;
echo       Removed warning regarding broken GPAC install, which was fixed;
echo       Updated a couple links and pending tasks;
echo       Improved help screen.
echo 1.6 - Helder Magalhaes, August 2010
echo       Updated Ssrc SVG plug-in to 1.9.2.8;
echo 1.5 - Helder Magalhaes, November 2009
echo       Added Ssrc SVG plug-in option;
echo       Added Renesis V3 plug-in option;
echo       Bumped GPAC version to 0.4.6;
echo       Reordered plug-ins based in Jeff Schiller's SVG support table;
echo       Fixed disabling SMT;
echo       Fixed issue when the operating system location has spaces (rare);
echo       Fixed a few typos.

echo 1.4 - Helder Magalhaes, December 2008
echo       Added GPAC 0.4.5-dev plug-in option;
echo       Added support for Renesis Windows File Explorer Plug-in;
echo       Added option to disable supported plug-ins;
echo       Changed plug-in listing order (sorted descending by SVG support);
echo       Bumped Renesis version to 1.1.1;
echo       Changed SVGMapToolkit to SMT (a.k.a.) for command-line usage;
echo       Bumped SMT version to 0.8;
echo       Minor command line improvements and text corrections.
if not "%CONSOLE_MODE%"=="true" (
  echo.
  pause
  cls
)
echo 1.3 - Helder Magalhaes, June 2008
echo       Added SVG Map Tookit 0.6 plug-in option;
echo       Bumped Renesis version to 1.1;
echo       Added command-line features (plug-in selection, console mode);
echo       Changed support options (change log split, about changed to help);
echo       User interface tweaks;
echo       Change log corrections.
echo 1.2 - Helder Magalhaes, May 2008
echo       Added Renesis 1.0 plug-in option;
echo       Added support options (download locations and about);
echo       Fixed CSV option for locales other than German;
echo       Renamed filename to match utility name;
echo       Several user interface tweaks.
echo 1.1 - Helder Magalhaes, February 2006
echo       Improved ASV6 support;
echo       Minor user interface improvements.
echo 1.0 - Georg Held, October 2003
echo       Initial version.
echo.
pause
goto menu

:installer
if not "%CONSOLE_MODE%"=="true" (
  cls
)
echo.
echo Installer download locations
echo ----------------------------
echo Adobe SVG Viewer 6.0 Development Release 1 (a.k.a. ASV6):
echo "http://www.adobe.com/svg/viewer/install/beta.html"
echo.
echo Adobe SVG Viewer 3.03 (a.k.a. ASV3):
echo "http://www.adobe.com/svg/viewer/install/main.html"
echo.
echo GPAC:
echo "http://gpac.wp.institut-telecom.fr/downloads/gpac-nightly-builds/#Windows%2032%20bits"
echo.
echo Ssrc SVG:
echo "http://www.savarese.com/software/svgplugin/"
echo.
echo Corel SVG Viewer 2.1 (a.k.a. CSV):
echo "http://www.corel.com/servlet/Satellite?pagename=Corel2/Products/Content&pid=1047023276653&cid=1047023286996"
echo.
echo Renesis Player 1.1.1:
echo "http://www.examotion.com/?id=product_player_download"
echo.
echo Renesis Player V3 (a.k.a. V3):
echo "http://www.examotion.com/index.php?id=v3"
echo.
echo SVG Map Toolkit:
echo "http://blog.svg-map.com/2007/09/svg_map_toolkit.html"
echo.
echo Abbra Pagefire:
echo "http://www.pagefire.com/"
echo.
echo Extensive, up-to-date list of SVG implementations:
echo "http://wiki.svg.org/index.php/Viewer_Matrix"
echo.
pause
goto menu

:quit
endlocal